package com.ruoyi.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.nursing.domain.NursingProject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.nursing.service.INursingProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import io.swagger.annotations.Api; // 引入Swagger依赖
import io.swagger.annotations.ApiOperation; // 引入Swagger依赖
import io.swagger.annotations.ApiParam; // 引入Swagger依赖

/**
 * 护理项目Controller
 *
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/serve/project")
@Api(tags = "护理项目管理接口") // 添加Swagger类注解
public class NursingProjectController extends BaseController
{
    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('serve:project:list')")
    @GetMapping("/list")
    @ApiOperation("查询护理项目列表") // 添加Swagger方法注解
    public TableDataInfo list(
        @ApiParam(name = "nursingProject", value = "护理项目查询条件") NursingProject nursingProject) // 添加Swagger参数注解
    {
        startPage();
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    /**
     * 导出护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('serve:project:export')")
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出护理项目列表到Excel") // 添加Swagger方法注解
    public void export(
        @ApiParam(name = "response", value = "HTTP响应对象") HttpServletResponse response,
        @ApiParam(name = "nursingProject", value = "护理项目查询条件") NursingProject nursingProject) // 添加Swagger参数注解
    {
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        ExcelUtil<NursingProject> util = new ExcelUtil<NursingProject>(NursingProject.class);
        util.exportExcel(response, list, "护理项目数据");
    }

    /**
     * 获取护理项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('serve:project:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("根据ID获取护理项目详情") // 添加Swagger方法注解
    public R<NursingProject> getInfo(
        @ApiParam(name = "id", value = "护理项目唯一标识") @PathVariable("id") Long id) // 添加Swagger参数注解
    {
        NursingProject nursingProject = nursingProjectService.selectNursingProjectById(id);
        return R.ok(nursingProject);
//        return success(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 新增护理项目
     */
    @PreAuthorize("@ss.hasPermi('serve:project:add')")
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增护理项目") // 添加Swagger方法注解
    public AjaxResult add(
        @ApiParam(name = "nursingProject", value = "需要新增的护理项目数据") @RequestBody NursingProject nursingProject) // 添加Swagger参数注解
    {
        return toAjax(nursingProjectService.insertNursingProject(nursingProject));
    }

    /**
     * 修改护理项目
     */
    @PreAuthorize("@ss.hasPermi('serve:project:edit')")
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改护理项目") // 添加Swagger方法注解
    public AjaxResult edit(
        @ApiParam(name = "nursingProject", value = "需要修改的护理项目数据") @RequestBody NursingProject nursingProject) // 添加Swagger参数注解
    {
        return toAjax(nursingProjectService.updateNursingProject(nursingProject));
    }

    /**
     * 删除护理项目
     */
    @PreAuthorize("@ss.hasPermi('serve:project:remove')")
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除多个护理项目") // 添加Swagger方法注解
    public AjaxResult remove(
        @ApiParam(name = "ids", value = "需要删除的护理项目ID数组") @PathVariable Long[] ids) // 添加Swagger参数注解
    {
        return toAjax(nursingProjectService.deleteNursingProjectByIds(ids));
    }
}
